package com.base.exception;

import cn.dev33.satoken.exception.NotLoginException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(NotLoginException.class)
    public ModelAndView handleNotLoginException(NotLoginException e) {
        // 记录异常日志（可选）
        System.out.println("未登录异常: " + e.getMessage());

        // 创建重定向视图
        ModelAndView modelAndView = new ModelAndView("redirect:/login");
        return modelAndView;
    }
}
